package com.imm.da.utils

import android.content.Context
import android.os.Looper
import android.widget.Toast

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2020 wasu company, All rights reserved.
 * <p>------------------------------------------------------
 * <p>
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2024/3/22
 */
object ToastHelper {

    private var mToast : Toast? = null

    private fun isMain() : Boolean {
        return Looper.getMainLooper() != Looper.myLooper()
    }

    fun toast(context : Context, message : String){
        if (isMain()){
            return
        }
        mToast?.run {
            duration = Toast.LENGTH_SHORT
            setText(message)
            show()
            return
        }
        mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
        mToast?.show()
    }

    fun toastLong(context : Context, message : String){
        if (isMain()){
            return
        }
        mToast?.run {
            duration = Toast.LENGTH_LONG
            setText(message)
            show()
            return
        }
        mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
        mToast?.show()
    }

}